//
//  FansTableViewCell.m
//  艾听歌
//
//  Created by dllo on 16/5/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FansTableViewCell.h"
#import "RecommendCollectionViewCell.h"
#import "SuperViewController.h"

static NSString *const buttonCell = @"buttonCell";

@interface FansTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong)UICollectionViewFlowLayout *flowLayout;

@end

@implementation FansTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  
    if (self) {
        
        [self createCollectionView];
    }
    return self;
}
- (void)createCollectionView
{
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3, self.contentView.frame.size.height);
    
     self.flowLayout.minimumInteritemSpacing = 0.5;

     self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout: self.flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
//    self.collectionView.backgroundColor = [UIColor grayColor];
    self.collectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9C9C9C);

    
    // 注册CollectionView
    [self.collectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:buttonCell];
   
    
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3 - 2  , self.contentView.frame.size.height);
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:buttonCell forIndexPath:indexPath];
    NSArray *array = @[@"歌单",@"排行榜",@"歌手"];
    
    cell.titleLable.text = array[indexPath.item];
    cell.titleLable.font = [UIFont systemFontOfSize:14];
    cell.titleLable.textAlignment = YES;
    cell.titleLable.textColor = [UIColor blackColor];
    cell.imageView.image = [UIImage imageNamed:array[indexPath.item] ];
    
    
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item == 0) {
        
        self.toHotVCBlock();
    }
    if (indexPath.item == 1) {
        self.toListBlock();
    }
    if (indexPath.item == 2) {
        self.toStarBlock();
    }
}




@end
